﻿using Kingdee.BOS;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.Core;
using Kingdee.BOS.ServiceHelper;

namespace DzInfo.DzSchedule.GXD
{
    public class PPBOM : IScheduleService
    {
        public void Run(Context ctx, Schedule schedule)
        {
            string sql = GetSql();
            DBServiceHelper.Execute(ctx, sql);
        }

        private string GetSql()
        {
            string sql = string.Format(@"/*dialect*/ 
            UPDATE T1
              SET 
                  T1.F_QFDB_YXHSLKLSH = T1.FMUSTQTY / T0.FQTY * T3.FSTOCKINQUAAUXQTY, 
                  T1.F_QFDB_ZZCLSLKLSH = T4.FPICKEDQTY - (T1.FMUSTQTY / T0.FQTY * T3.FSTOCKINQUAAUXQTY)
            FROM T_PRD_PPBOM T0
                 JOIN T_PRD_PPBOMENTRY T1 ON T1.FID = T0.FID
                 JOIN T_PRD_MOENTRY T2 ON T2.FENTRYID = T0.FMOENTRYID
                 JOIN T_PRD_MOENTRY_A T3 ON T3.FENTRYID = T2.FENTRYID
                 JOIN T_PRD_PPBOMENTRY_Q T4 ON T4.FENTRYID = T1.FENTRYID
            WHERE 1 = 1
                  AND T3.FSTATUS < 6 ");
            return sql;
        }
    }
}
